﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace NetPE.Dialogs
{
    public class CollectionDialog<T> : BaseDialog where T : class, new()
    {
        public CollectionDialog(IList<T> val)
            : base(val)
        {
            if (Type.GetTypeCode(typeof(T)) != TypeCode.Object)
            {
                PrimitiveCollectionEditor<T> etr = new PrimitiveCollectionEditor<T>();
                etr.Dock = DockStyle.Fill;
                this.Controls.Add(etr);
                etr.Object = val;
            }
            else if (typeof(T).GetConstructor(Type.EmptyTypes) != null)
            {
                CollectionEditor<T> etr = new CollectionEditor<T>();
                etr.Dock = DockStyle.Fill;
                this.Controls.Add(etr);
                etr.Object = val;
            }
            else
            {
                ReadonlyCollectionEditor<T> etr = new ReadonlyCollectionEditor<T>();
                etr.Dock = DockStyle.Fill;
                this.Controls.Add(etr);
                etr.Object = val;
            }
            this.ClientSize = new Size(650, 350);
        }
    }
}
